package com.ziyun.pop.modules.mercharReport.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ziyun.pop.common.e.mercharReport.AdvancePaymentEnum;
import com.ziyun.pop.common.utils.JsonUtils;
import com.ziyun.pop.modules.mercharReport.dao.ReportAdvanceDeatilDao;
import com.ziyun.pop.modules.mercharReport.entity.ReportAdvanceDeatilEntity;
import com.ziyun.pop.modules.mercharReport.entity.ReportAdvanceDeatilVO;
import com.ziyun.pop.modules.mercharReport.service.ReportAdvanceDeatilService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("reportAdvanceDeatilService")
public class ReportAdvanceDeatilServiceImpl extends ServiceImpl<ReportAdvanceDeatilDao, ReportAdvanceDeatilEntity> implements ReportAdvanceDeatilService {

    @Autowired
    private ReportAdvanceDeatilDao reportAdvanceDeatilDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<ReportAdvanceDeatilEntity> page = (Page<ReportAdvanceDeatilEntity>) this.page(
                new Query<ReportAdvanceDeatilEntity>(params).getPage(),
                new QueryWrapper<ReportAdvanceDeatilEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R list(Map<String, Object> params) {
        Page<ReportAdvanceDeatilVO> page = new Page<>();
        page.setCurrent(Integer.valueOf(params.get("page").toString()));
        page.setSize(Integer.valueOf(params.get("limit").toString()));
        List<ReportAdvanceDeatilVO> list = reportAdvanceDeatilDao.list(page, params);
        page.setRecords(list);
        PageUtils pageUtils = new PageUtils(page);

        Map<String, List> mapEnum = new HashMap<>();
        mapEnum.put("advancePaymentEnum", JsonUtils.enumToList(AdvancePaymentEnum.class));
        return R.ok().put("page", pageUtils).put("userData", mapEnum);
    }

    @Override
    public List<ReportAdvanceDeatilVO> exportExcel(Map<String, Object> params) {
        return reportAdvanceDeatilDao.list(params);
    }

}
